🧪 [testing improvement] tracker telemetry snapshot mapping#11
🧪 [testing improvement] tracker telemetry snapshot mapping#11tcrypt25519 wants to merge 2 commits intomasterfrom
Conversation
This commit adds a unit test in `crates/mempooloracle/src/runtime.rs` to verify that atomic telemetry values in `RuntimeTelemetry` are correctly mapped to `TrackerTelemetrySnapshot` when `TrackerTelemetry::snapshot()` is called. The test covers: - Transport kind mapping - Atomic counters for pending transactions and blocks - Values recorded via record_backfill_size, record_block, and P2P-specific methods.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Changed Files
|
There was a problem hiding this comment.
Code Review
This pull request adds a unit test for telemetry snapshots in crates/mempooloracle/src/runtime.rs. A compilation error was identified in the new test because it attempts to access the private inner field of TrackerTelemetry from within a submodule.
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_telemetry_snapshot() { | ||
| let telemetry = Arc::new(RuntimeTelemetry::new(TransportKind::P2p)); | ||
| let tracker_telemetry = TrackerTelemetry { | ||
| inner: telemetry.clone(), | ||
| }; | ||
|
|
||
| telemetry.record_backfill_size(100); | ||
| telemetry.record_pending_seen(); | ||
| telemetry.record_pending_seen(); | ||
| telemetry.record_block(50, 1000); | ||
| telemetry.record_p2p_peer_count(5); | ||
| telemetry.record_p2p_announcement(); | ||
| telemetry.record_p2p_announcement(); | ||
| telemetry.record_p2p_announcement(); | ||
| telemetry.record_p2p_import(); | ||
|
|
||
| let snapshot = tracker_telemetry.snapshot(); | ||
|
|
||
| assert_eq!(snapshot.transport_kind, TransportKind::P2p); | ||
| assert_eq!(snapshot.pending_seen, 2); | ||
| assert_eq!(snapshot.block_count, 1); | ||
| assert_eq!(snapshot.last_block_txs, 50); | ||
| assert_eq!(snapshot.last_block_gas_used, 1000); | ||
| assert_eq!(snapshot.initial_backfill_txs, 100); | ||
| assert_eq!(snapshot.p2p_peer_count, 5); | ||
| assert_eq!(snapshot.p2p_announced_txs, 3); | ||
| assert_eq!(snapshot.p2p_imported_txs, 1); |
There was a problem hiding this comment.
The test will fail to compile because it attempts to instantiate TrackerTelemetry using its private field inner from within the tests submodule. In Rust, private fields are only accessible within the module where the struct is defined, and submodules are considered separate modules for this purpose. To fix this, you can move the test function out of the mod tests block and place it directly in the parent module, which allows it to access the private field. Alternatively, you could change the visibility of the inner field to pub(crate) in its definition.
References
- Actionable only. Only leave a comment for bugs, vulnerabilities, or major performance issues. (link)
- Actionable only. Only leave a comment for bugs, vulnerabilities, or major performance issues.
🎯 What: The testing gap addressed
Untested mapping of
RuntimeTelemetry(atomic values) toTrackerTelemetrySnapshotinTrackerTelemetry::snapshot().📊 Coverage: What scenarios are now tested
TransportKind.u64andusizevalues:pending_seenblock_countlast_block_txslast_block_gas_usedinitial_backfill_txsp2p_peer_countp2p_announced_txsp2p_imported_txs✨ Result: The improvement in test coverage
Ensures that telemetry data collected during the tracker runtime is accurately reported to consumers of the snapshot API, preventing future regressions in data reporting.
PR created automatically by Jules for task 16709284375591940968 started by @tcrypt25519